Statement 3, PRINT COUNT
, will be highlighted.
The LOOP statement sends execution back to the first statement in the
loop body.
If you said that the DO
statement would be highlighted, that was a
good answer. I think that it is not highlighted is just a quirk of
the system.
The following program adds something to the DO
statement:
' Loop with a loop condition ' LET COUNT = 0 'Statement 1 DO WHILE COUNT <= 2 'Statement 2 PRINT COUNT 'Statement 3 LET COUNT = COUNT + 1 'Statement 4 LOOP END
COUNT <= 2
is called a loop condition.
It says under what condition the loop body
(statements 3 and 4) will execute.
The loop body is executed only if COUNT
is less than or equal to 2.
If the loop body can't start,
the next statement after LOOP
is executed.
Here is how the program works:
DO
statement:
COUNT
is less than or equal to 2
so the loop body is executed.
PRINT COUNT
prints 0.COUNT
,
so now COUNT is 1.LOOP
sends execution back to the DO
.DO
statement:
COUNT
is less than or equal to 2
so the loop body is executed.
PRINT COUNT
prints 1.COUNT
,
so now COUNT is 2.LOOP
send execution back to the DO
.DO
statement:
COUNT
is less than or equal to 2
so the loop body is executed.
PRINT COUNT
prints 2.COUNT
,
so now COUNT is 3.LOOP
sends execution back to the DO
.DO
statement:
COUNT
is NOT less than or equal to 2
so the loop body is skipped over.
The loop ended gracefully.
Just before
the loop body COUNT
is tested.
If it is less than or equal to two,
the loop body is executed.
Otherwise the statement after LOOP
is executed.